package com.jpa.ordering.collections.tutorial;

import com.jpa.ordering.collections.tutorial.domain.Album;
import com.jpa.ordering.collections.tutorial.domain.Artist;
import com.jpa.ordering.collections.tutorial.service.ArtistService;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class JpaOrderingCollectionsTutorial {

    public static void main(String[] args) {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("JpaOrderingCollectionsTutorial");
        EntityManager em = emf.createEntityManager();
        ArtistService artistService = new ArtistService(em);

        System.out.println("--- Find artist and order its albums ---");
        Artist artist = artistService.findArtist(1);
        System.out.println(String.format("Found artist: %s", artist));
        for (Album album : artist.getAlbums()) {
            System.out.println(String.format("Artist album: %s", album));
        }
    }
}
